import CryptoJS from 'crypto-js'
import { AES_CONFIG } from '@/config/aesConfig'

export default {
  decrypt(data, AES_KEY = AES_CONFIG.KEY36, IV = AES_CONFIG.IV36) {
    const key = CryptoJS.enc.Utf8.parse(AES_KEY)
    const iv = CryptoJS.enc.Utf8.parse(IV)
    const decrypt = CryptoJS.AES.decrypt(data, key, {
      iv,
      mode: CryptoJS.mode.CBC,
      padding: CryptoJS.pad.Pkcs7,
    }).toString(CryptoJS.enc.Utf8)
    return decrypt
  },

  encrypt(data, AES_KEY = AES_CONFIG.KEY36, IV = AES_CONFIG.IV36) {
    const key = CryptoJS.enc.Utf8.parse(AES_KEY)
    const iv = CryptoJS.enc.Utf8.parse(IV)
    const encrypted = CryptoJS.AES.encrypt(data, key, {
      iv,
      mode: CryptoJS.mode.CBC,
      padding: CryptoJS.pad.Pkcs7,
    })
    return encrypted.toString()
  },

  decryptsixteen(data, AES_KEY = AES_CONFIG.KEY16, IV = AES_CONFIG.IV16) {
    const key = CryptoJS.enc.Utf8.parse(AES_KEY)
    const iv = CryptoJS.enc.Utf8.parse(IV)
    const decrypt = CryptoJS.AES.decrypt(data, key, {
      iv,
      mode: CryptoJS.mode.CBC,
      padding: CryptoJS.pad.Pkcs7,
    }).toString(CryptoJS.enc.Utf8)
    return decrypt
  },

  encryptsixteen(data, AES_KEY = AES_CONFIG.KEY16, IV = AES_CONFIG.IV16) {
    const key = CryptoJS.enc.Utf8.parse(AES_KEY)
    const iv = CryptoJS.enc.Utf8.parse(IV)
    const encrypted = CryptoJS.AES.encrypt(data, key, {
      iv,
      mode: CryptoJS.mode.CBC,
      padding: CryptoJS.pad.Pkcs7,
    })
    return encrypted.toString()
  },
}

